function [y,signal]=basictral (LN,L,SNR)
%方波成型的基带传输系统
%返回值y为误码率，signal为发送信号


data = randi([0,1], 1,LN);
%产生随机数作为发送数据
data_bipolar = 1 -2*data;
%将数据转为双极性序列，0对应于1,1对应于-1
data_upsample =  upsample(data_bipolar,L);
qart_fir = ones(1,8);
%产生方波
Rsend = conv(data_upsample,qart_fir);
%完成方波成型
Rrecv = awgn(Rsend,SNR,'measured');
%通过信道，加噪
data_rec = conv(Rrecv,qart_fir);
%接收端通过接收匹配滤波器
rdata_biplolar = downsample(data_rec,L,7);
%采样
rdata(rdata_biplolar<0)=1;rdata(rdata_biplolar>0)=0;
Rdata = rdata(1:LN);
c=0;
%误码率计算
for n=1:LN
    if (data(n) ~= Rdata(n))
        c=c+1;
    end
end
y=c/LN;
signal = Rsend;